package com.binarysoft.service.obj;

import java.util.Collection;
import java.util.Map;

import com.binarysoft.service.obj.dao.ObjectEntity;
import com.binarysoft.service.obj.dao.ObjectProperty;
import common.framework.dsb.DynamicService;

public interface ObjectService extends DynamicService {

	long EMPTY_ID = 0l;

	int EMPTY_HIERARCHY = 0;

	boolean existsObject(long objId);

	void setObjectActiveStatus(long objId, boolean active) throws Exception;

	void setObjectActiveStatus(Collection<Long> objIds, boolean active) throws Exception;

	/**
	 * 获取所有根对象
	 * 
	 * @return
	 */
	Collection<ObjectEntity> getRootObjects();

	/**
	 * 获取所有激活的根对象
	 * 
	 * @return
	 */
	Collection<ObjectEntity> getActivedRootObjects();

	/**
	 * 获取所有激活的根对象的ID
	 * 
	 * @return
	 */
	Collection<Long> getRootObjectIds();

	/**
	 * 根据对象类型获取所有根对象
	 * 
	 * @param typeID
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectEntity> getRootObjectsByType(String typeID) throws Exception;

	/**
	 * 获取指定类型的所有根对象的ID
	 * 
	 * @param typeID
	 * @return
	 * @throws Exception
	 */
	Collection<Long> getRootObjectIdsByType(String typeID) throws Exception;

	/**
	 * 获取按照类型分组的所有根对象
	 * 
	 * 
	 * @return Key: type ID, value: root Objects
	 */
	Map<String, Collection<ObjectEntity>> getTypeGroupedRootObjects();

	/**
	 * Get all Objs.
	 * 
	 * @return
	 */
	Collection<ObjectEntity> getAllObjects();

	/**
	 * get all Obj with given typeID.
	 * 
	 * @param typeID
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectEntity> getObjectsByType(String typeID) throws Exception;

	/**
	 * Get Obj IDs with given typeID.
	 * 
	 * @param typeID
	 * @return
	 * @throws Exception
	 */
	Collection<Long> getObjectIdsByType(String typeID) throws Exception;

	/**
	 * Get parent objects (sorted from root Obj to direct parent)
	 * 
	 * @param objId
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectEntity> getAllParentObjects(long objId) throws Exception;

	/**
	 * Get direct sub objects.
	 * 
	 * @param objId
	 * @return
	 */
	Collection<ObjectEntity> getSubObjects(long objId);

	/**
	 * Get direct sub objects with given type
	 * 
	 * @param objId
	 * @param neType
	 * @return
	 */
	Collection<ObjectEntity> getSubObjects(long objId, String objType);

	/**
	 * get sub Objs grouped by Obj type ID
	 * 
	 * @param objId
	 * @return Key: Obj type ID, value: Objs
	 */
	Map<String, Collection<ObjectEntity>> getTypeGroupedSubObjects(long objId);

	Collection<Long> getSubObjectIds(long objId);

	Collection<ObjectEntity> getAllSubObjects(long objId);

	/**
	 * Get all sub Objs with given type ID
	 * 
	 * @param objId
	 *            long
	 * @param subNeTypeID
	 *            String
	 * @return
	 */
	Collection<ObjectEntity> getAllSubObjsByType(long objId, String subObjTypeId);

	/**
	 * Get all sub-nes in map format(grouped by obj type )
	 * 
	 * @param objId
	 * @return key: type ID, value: a collection of Objs with same type ID
	 */
	Map<String, Collection<ObjectEntity>> getTypeGroupedAllSubObjects(long objId);

	Collection<Long> getAllSubObjectIds(long objId);

	/**
	 * get Obj by Obj ID.
	 * 
	 * @param objId
	 * @return
	 */
	ObjectEntity getObject(long objId);

	/**
	 * Get Obj objects with specified IDs.
	 * 
	 * @param objIds
	 * @return
	 */
	Collection<ObjectEntity> getObjects(Collection<Long> objIds);

	long addObject(ObjectEntity ne) throws Exception;

	void addObject(Collection<ObjectEntity> entities) throws Exception;

	long addRootObject(String name, String desc, String addr, String typeId) throws Exception;

	/**
	 * Current Obj and all it's SUB-Objs will be deleted recursively
	 * 
	 * @param objId
	 * @throws Exception
	 */
	void deleteObject(long objId) throws Exception;

	/**
	 * Objs and all it's SUB-Objs will be deleted recursively
	 * 
	 * @param nes
	 * @throws Exception
	 */
	void deleteObject(Collection<Long> objIds) throws Exception;

	void updateObject(ObjectEntity ne) throws Exception;

	void updateObject(Collection<ObjectEntity> nes) throws Exception;

	/******** Obj Prop ************/

	boolean existsProperty(long objId, String propID);

	Collection<ObjectProperty> getPropties(long objId) throws Exception;

	ObjectProperty getProperty(long objId, String propID) throws Exception;

	/**
	 * 返回具备给定属性ID的Obj
	 * 
	 * @param propID
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectEntity> hasProperty(String propID) throws Exception;

	/**
	 * 返回具备给定属性ID和值的Obj
	 * 
	 * @param propID
	 * @param propValue
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectEntity> hasProperty(String propID, String propValue) throws Exception;

	/**
	 * 给定属性集合，返回已经存在的属性
	 * 
	 * @param props
	 * @return
	 */
	Collection<ObjectProperty> existsProperties(Collection<ObjectProperty> props);

	/**
	 * 给定属性集合，返回没有被锁定的属性
	 * 
	 * @param props
	 * @return
	 * @throws Exception
	 */
	Collection<ObjectProperty> unlockedProperties(Collection<ObjectProperty> props) throws Exception;

	/**
	 * 删除某个网元的所有属性
	 * 
	 * @param objId
	 * @throws Exception
	 */
	void deleteProperties(long objId) throws Exception;

	void deleteProperty(long objId, String propID) throws Exception;

	/**
	 * 批量删除一批网元的同一属性
	 * 
	 * @param objIds
	 * @param propID
	 * @throws Exception
	 */
	void deleteProperties(Collection<Long> objIds, String propID) throws Exception;

	void addProperty(long objId, String propID, String propName, String propValue) throws Exception;

	/**
	 * 批量增加网元属性，属性集合中的属性对象可以是不同网元的属性, 新增属性默认是未锁定的
	 * 
	 * @param props
	 *            属性集合
	 * @throws Exception
	 */
	void addProperties(Collection<ObjectProperty> props) throws Exception;

	/**
	 * Save properties
	 * 
	 * @param props
	 * @throws Exception
	 */
	void saveProperties(Collection<ObjectProperty> props) throws Exception;

	/**
	 * 更新网元的属性(proName 和 propValue)，如果属性被锁定，则无法更新
	 * 
	 * @param objId
	 * @param propID
	 * @param propName
	 * @param propValue
	 * @throws Exception
	 */
	void updateProperty(long objId, String propID, String propName, String propValue) throws Exception;

	/**
	 * 批量更新多个网元的属性(proName 和 propValue), 如果属性被锁定，则无法更新
	 * 
	 * @param props
	 * @throws Exception
	 */
	void updateProperties(Collection<ObjectProperty> props) throws Exception;

	/**
	 * 锁定网元某个属性
	 * 
	 * @param objId
	 * @param propID
	 * @throws Exception
	 */
	void lockProperty(long objId, String propID) throws Exception;

	/**
	 * 批量锁定网元属性
	 * 
	 * @param props
	 * @throws Exception
	 */
	void lockProperties(Collection<ObjectProperty> props) throws Exception;

	/**
	 * 解锁网元属性
	 * 
	 * @param objId
	 * @param propID
	 * @throws Exception
	 */
	void unlockProperty(long objId, String propID) throws Exception;

	/**
	 * 解锁一批网元属性
	 * 
	 * @param props
	 * @throws Exception
	 */
	void unlockProperties(Collection<ObjectProperty> props) throws Exception;
}
